﻿package com.msjt.dao;

import java.util.List;
import com.msjt.base.BaseDAO;
import com.msjt.entity.Picture;

public class PictureDAO extends BaseDAO {
	//得到图片的记录数
	public Integer getPictureCount(){
		String hql="select count(p.picId) from Picture as p";
		return this.getTotalCount(hql, null);
	}
	//主页面加载图片地址，5-9张，按上传时间排序
	@SuppressWarnings("unchecked")
	public List<Picture> getPictureIndex(){
		String hql="select p from Picture as p order by p.picDate desc";
		return (List<Picture>) this.searchByPage(hql, null, 1, 6);
	}
	//前台后台查看图片列表，分页
	@SuppressWarnings("unchecked")
	public List<Picture> getPicturePage(int pageIndex,int pageSize){
		String hql="select p from Picture as p order by p.picDate desc";
		return (List<Picture>) this.searchByPage(hql, null, pageIndex, pageSize);
	}
	//新上传图片
	public boolean addPicture(Picture picture){
		return this.save(picture);
	}
	//修改图片信息
	public boolean updatePicture(Picture picture){
		return this.saveOrUpdate(picture);
	}
	//删除图片
	public boolean deletePicture(Picture picture){
		return this.deleteById(picture.getPicId());
	}
	//根据ID得到图片的详细信息
	public Picture getOnePicture(Picture picture){
		return (Picture) this.findById(picture.getPicId());
	}
	/**
	 * 批量删除
	 * @param idString id的字符串，用“,”号隔开
	 * @return
	 */
	public boolean deleteMore(String idString){
		String hql="delete Picture as pic where pic.picId in ("+idString+")";
		return this.updateByHql(hql, null);
	}
	//批量删除时得到路径
		@SuppressWarnings({ "unchecked" })
		public List<String> getPicturePath(String idString){
			String hql="select pic.picPath from Picture as pic where pic.picId in ("+idString+")";
			return (List<String>) this.searchByHQL(hql, null);
		}
}
